#define _CRT_SECURE_NO_WARNINGS 1
#include <vector>
#include <unordered_set>
using namespace std;
class Solution {
public:
    int maxLength(vector<int>& arr)
    {
        if (arr.size() < 2) return arr.size();
        int left = 0, right = 1;
        unordered_set<int> us;
        us.insert(arr[0]);
        int ret = 1;
        while (right < arr.size())
        {
            while (us.find(arr[right]) != us.end())
            {
                us.erase(arr[left]);
                ++left;
            }
            us.insert(arr[right]);
            if (us.size() > ret)
            {
                ret = us.size();
            }
            ++right;
        }
        return ret;
    }
};